FROM harbor.cloudos.svolt.cn/svolt-devops/maven:3.6-jdk-8-slim AS builder

LABEL version="1.0" \
    maintainer="vzer.zhang"  \
    description="for maven build jar package"

WORKDIR /builder

# download maven dependencies
ADD pom.xml ./
ADD trace-action/pom.xml ./trace-action/pom.xml
ADD trace-api/pom.xml ./trace-api/pom.xml
ADD trace-service/pom.xml ./trace-service/pom.xml
ADD settings.xml ./
RUN mvn -s settings.xml dependency:go-offline -B

# build jar package
ADD . ./
RUN mvn clean package -s settings.xml -Dmaven.test.skip=true

# build app env
FROM  harbor.cloudos.svolt.cn/svolt-devops/openjdk:8u342-slim-bullseye
LABEL version="1.0" \
    maintainer="vzer.zhang"  \
    description="builder image for trace-action"

WORKDIR /home

# Define environment variables.
ENV TZ="Asia/Shanghai"
ENV NACOS_ADDR=''
ENV NACOS_NAMESPACE=''
ENV NACOS_GROUP='mysql'
ENV NACOS_DATAID=''
ENV JAVA_XMS='1G'
ENV JAVA_XMX='2G'
ENV JAVA_OPTS=''

COPY --from=builder /builder/trace-action/target/*.jar .

# Run the jar
CMD java \
-Dspring.cloud.nacos.config.server-addr=$NACOS_ADDR \
-Dspring.cloud.nacos.config.group=$NACOS_GROUP  \
-Dspring.cloud.nacos.config.namespace=$NACOS_NAMESPACE \
-Djava.security.egd=file:/dev/./urandom \
-Dfile.encoding=utf-8 \
-XX:+HeapDumpOnOutOfMemoryError \
-Xms$JAVA_XMS \
-Xmx$JAVA_XMX \
$JAVA_OPTS \
-jar *.jar